package generator.statements;

import generator.addons.SimpleDataGenerator;
import generator.collections.OfferTable;
import java.sql.Date;
import java.util.Random;

/**
 * Offer SQL record mapper.
 * 
 * @author Necro
 * @author Marek Snopkowski <snpy@snpy.info>
 * @version 12.04.2008
 */
public class Offer extends Statement
{
    private int offerID;
    
    private Accomodation accomodation;    
    private Transport transport;
    
    private String name;
    private String description;
    private float price;
    
    private int placesLimit;
    private Date startDate;
    private int duration;

    @Override
    public int getId() {
        return offerID;
    }    
    
    public Object[] getFieldsValueCollection()
    {
        return new Object[]{ offerID, accomodation.getId(), transport.getId(), name, 
                description, price, placesLimit, startDate, duration };
    }
    
    public float getPrice()
    {
        return price;
    }
    
    public String getFieldsNameSet()
    {
        return "[offer_id], [accomodation_id], [transport_id], [name], " +
                "[description], [price], [place_limits], [start_date], [duration]";
    }
    
    public int getPlacesLimit() 
    {
        return placesLimit;
    }

    public Accomodation getAccomodation() {
        return accomodation;
    }

    public int getDuration() {
        return duration;
    }

    public Date getStartDate() {
        return startDate;
    }
    
    
    public Offer(Accomodation accomodation, Transport transport, String name, String description, 
            float price, int place_limits, Date startDate, int duration) {
        
        this.offerID = OfferTable.autoincrement();
        
        this.accomodation = accomodation;
        this.transport    = transport;
        this.name         = name;
        this.description  = description;
        this.price        = price;
        this.placesLimit  = place_limits;
        this.startDate    = startDate;
        this.duration     = duration;
    }

    public void setPlacesLimit(int placesLimit) {
        this.placesLimit = placesLimit;
    }
    
    public static Offer genRand(Accomodation accomodation, Transport transport) {
        Random rand = new Random();
        String[] vacatPrefs = { "Wczasy Jak Ze Snu", "Niezapomniane chwile", 
                "Wycieczka Twoich Marzeń", "Tylko u nas"};
        
        Date startDate     = SimpleDataGenerator.getDate();
        int duration       = SimpleDataGenerator.getDuration();
        int placeLimits    = SimpleDataGenerator.getPlaceLimits();
        String name        = vacatPrefs[rand.nextInt(vacatPrefs.length)] + " w " + accomodation.getName();
        String description = name.toLowerCase() + " od " + startDate.toString() + " przez " + duration + " dni";
        float price        = SimpleDataGenerator.getMoneyHigh();
        
        Offer result = new Offer(accomodation, transport, name, description, price,
                placeLimits, startDate, duration);
        
        return result;
    }
    
     @Override
    public String getTableName()
    {
        return "offer";
    }
}
